package ch.ethz.fcl.metrobuzz.algorithm.network.shortest_path.public_transport;

import java.util.HashMap;
import java.util.Map;

import ch.ethz.fcl.metrobuzz.data.MBData;
import ch.ethz.fcl.metrobuzz.data.scene.basemap.Node;
import ch.ethz.fcl.metrobuzz.data.transit.Stop;

public class AllToAllDijkstraPublic {
	private MBData data;

	private OneToAllDijkstraPublic dijkstra;

	// key: source node
	// value key: destination node
	// value value: source to destination path
	private Map<Stop, Map<Stop, PathPublic>> nodeToNodePathMap;

	public AllToAllDijkstraPublic(MBData data) {
		this.data = data;
		this.dijkstra = new OneToAllDijkstraPublic(this.data);
		nodeToNodePathMap = new HashMap<Stop, Map<Stop, PathPublic>>();
	}

	public PathPublic getPath(Node source, Node end) {
		Stop sourceStop = data.getPublicTransit().getStopByNodeId(
				source.getId());
		Stop endStop = data.getPublicTransit().getStopByNodeId(end.getId());

		return getPath(sourceStop, endStop);
	}

	public PathPublic getPath(Stop source, Stop end) {
		Map<Stop, PathPublic> sourcePathMap = nodeToNodePathMap.get(source);

		if (sourcePathMap == null) {
			// System.out.println(source.getId() + "->" + end.getId());
			sourcePathMap = dijkstra.getShortestPath(source, Float.MAX_VALUE);

			nodeToNodePathMap.put(source, sourcePathMap);
		}
		return sourcePathMap.get(end);
	}
}
